﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using MySql.Data.Types;

namespace GirisSayfasi
{
    public partial class AnaSayfa : Form
    {
        MySqlConnection baglan = Connection.baglan;
        public static string Proje_Kodu;
        public ProjeTamamlama anaform;


        public AnaSayfa()
        {
            InitializeComponent();
        }
        ProjeKayit frmProjeKayit = new ProjeKayit();
        OgrenciKayit frmOgrenciKayit = new OgrenciKayit();
        OgretmenKayit frmOgretmenKayit = new OgretmenKayit();
        DersKayit frmDersKayit = new DersKayit();
        SinifKayit frmSinifKayit = new SinifKayit();
        ProjeTamamlama frmProjeTamamlama = new ProjeTamamlama();
        OgretmenDersKayit frmOgretmenDersKayit = new OgretmenDersKayit();


        private void button2_Click(object sender, EventArgs e)
        {
            frmProjeKayit.ShowDialog();
        }

        private void AnaSayfa_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                this.Close();
                Application.Exit();
            }

        }

        private void AnaSayfa_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            frmOgrenciKayit.ShowDialog();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            frmOgretmenKayit.ShowDialog();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            frmDersKayit.ShowDialog();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            frmSinifKayit.ShowDialog();
        }

        private void çıkışToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            frmProjeTamamlama.ShowDialog();
        }

        private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            ///MessageBox.Show(listView1.SelectedItems[0].Text.ToString());
            ///OgrenciKayit frm2 = new OgrenciKayit();
            frmProjeTamamlama.mskProjeKodu.Text = listView1.SelectedItems[0].Tag.ToString();
            frmProjeTamamlama.ShowDialog();
            frmProjeTamamlama.mskSinifKodu.Focus();
            
        }

        private void dersAtamaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmOgretmenDersKayit.ShowDialog();
        }

        private void AnaSayfa_Activated(object sender, EventArgs e)
        {
            listView1.Items.Clear();
            baglan.Open();
            MySqlCommand cmd1 = new MySqlCommand("select * from projelistesi where ProjeDurumu='1'", baglan);
            ////MySqlCommand cmd1 = new MySqlCommand("select * from acilansiniflar where AcilanProjeKodu = '" + mskProjeKodu.Text + "'", baglan);
            int sayi = Convert.ToInt32(cmd1.ExecuteScalar());
            if (sayi != 0)
            {

                MySqlDataReader oku1 = cmd1.ExecuteReader();
                if (oku1.HasRows)
                {
                    while (oku1.Read())
                    {
                        ListViewItem lst = new ListViewItem();
                        lst.Text = oku1["ProjeAdi"].ToString();
                        lst.SubItems.Add(oku1["ProjeMinimumKisiSayi"].ToString());
                        lst.SubItems.Add(oku1["ProjeMinimumKisiSayi"].ToString());
                        lst.SubItems.Add(oku1["ProjeBaslangicSaati"].ToString());
                        lst.SubItems.Add(oku1["ProjeBitisSaati"].ToString());
                        lst.SubItems.Add(oku1["ProjeBitis"].ToString());
                        lst.Tag = oku1["ProjeKodu"];
                        listView1.Items.Add(lst);

                    }
                }
                baglan.Close();

            }


        }

        private void AnaSayfa_Deactivate(object sender, EventArgs e)
        {
            baglan.Close();
        }
    }
}

